﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FirebirdSql.Data.FirebirdClient;

namespace University
{
    public partial class ASPIRANTY : University.LEARNERS
    {
        static string sqlSelect = "SELECT * FROM ASPIRANTY";
        FbDataAdapter da = new FbDataAdapter(sqlSelect, con);
        DataTable dt = new DataTable();

        public ASPIRANTY(TreeNode node, ContextMenuStrip s, string com, int id)
            : base(node, s, com, id)
        {
            InitializeComponent();
            node_id = Convert.ToInt32(mynode.Tag.ToString());
            da.Fill(dt);
            bindingSource1.DataSource = dt;
            textBox6.DataBindings.Add("Text", bindingSource1, "PIK_VYPYSKY");
            textBox7.DataBindings.Add("Text", bindingSource1, "PIK_VSTYPY_V_ASP");
            richTextBox2.DataBindings.Add("Text", bindingSource1, "TEMA_DYSERTATSII");
            textBox8.DataBindings.Add("Text", bindingSource1, "NAYKOVUJ_KERIVNYK");
            bindingSource1.Filter = "UNIQUE_NO =" + node_id;
            if (com == "Remove") { Remove("ASPIRANTY"); }
        }
        public override void Remove(string name)
        {
            base.Remove(name);
        }

        public override void UpdateForm()
        {
            OpenCon();
            UpdateFild("ASPIRANTY", "PIK_VYPYSKY", textBox6.Text);
            UpdateFild("ASPIRANTY", "PIK_VSTYPY_V_ASP", textBox7.Text);
            UpdateFild("ASPIRANTY", "TEMA_DYSERTATSII", richTextBox2.Text);
            UpdateFild("ASPIRANTY", "NAYKOVUJ_KERIVNYK", textBox8.Text);
            base.UpdateForm();
        }
        public override void InsertFild(string klas)
        {
            OpenCon();
            FbCommand cmdInsert = new FbCommand("INSERT INTO ASPIRANTY(UNIQUE_NO,PIK_VYPYSKY,PIK_VSTYPY_V_ASP,TEMA_DYSERTATSII,NAYKOVUJ_KERIVNYK) VALUES(@1,@2,@3,@4,@5)", con);
            cmdInsert.Parameters.AddWithValue("1", textBox1.Text);
            cmdInsert.Parameters.AddWithValue("2", textBox6.Text);
            cmdInsert.Parameters.AddWithValue("3", textBox7.Text);
            cmdInsert.Parameters.AddWithValue("4", richTextBox2.Text);
            cmdInsert.Parameters.AddWithValue("5", textBox8.Text);
            cmdInsert.ExecuteNonQuery();
            base.InsertFild(klas);
        }

    }
}